#ifndef AUTOCONTROL_H
#define AUTOCONTROL_H

#include <QWidget>
#include "TableWidgetForm.h"

struct AtTimeStruct
{
    int id;
    QString name;
    int initrotateswtime;
    int rotatejdtime;
    int defaults;

    // 获取结构体成员名的字符串
    QString toFieldNames() const {
        return QString("name,initrotateswtime,rotatejdtime,default");
    }

    // 获取结构体成员名的字符串
    QStringList toFieldTypes() const {
        QStringList _list;
        _list << typeid(name).name();
        _list << typeid(initrotateswtime).name();
        _list << typeid(rotatejdtime).name();
        _list << typeid(defaults).name();
        return _list;
    }
};

struct softStruct
{
    int soft_id;
    QString out_sensor;
    int in_sensor;

    // 获取结构体成员名的字符串
    QString toFieldNames() const {
        return QString("out_sensor,in_sensor");
    }

    // 获取结构体成员名的字符串
    QStringList toFieldTypes() const {
        QStringList _list;
        _list << typeid(out_sensor).name();
        _list << typeid(in_sensor).name();
        return _list;
    }
};

struct AreaStruct
{
    int id;
    QString name;
    double reduce;
    double invariant;
    int initrotatepr;
    int reducerotate;
    int riserotate;
    int lowlmit;
    int uplmit;
    QList<softStruct> softInfo;

    // 获取结构体成员名的字符串
    QString toFieldNames() const {
        return QString("name,reduce,invariant,initrotatepr,reducerotate,riserotate,lowlmit,uplmit");
    }

    // 获取结构体成员名的字符串
    QStringList toFieldTypes() const {
        QStringList _list;
        _list << typeid(name).name();
        _list << typeid(reduce).name();
        _list << typeid(invariant).name();
        _list << typeid(initrotatepr).name();
        _list << typeid(reducerotate).name();
        _list << typeid(riserotate).name();
        _list << typeid(lowlmit).name();
        _list << typeid(uplmit).name();
        return _list;
    }
};


class AutoControl
{
public:
    AutoControl();

    //初始化UI
    static void InitUI(const QString& fileName, QList<QPair<QWidget *, QString>>& widgets, QMap<int, QList<TableWidgetForm*>>& m_pTableWidgetFormMap);

    //保存
    static bool SaveUI(const QString& fileName, const QMap<int, QList<TableWidgetForm*>>& m_pTableWidgetFormMap);

    //解析
    static void Analysis(const QString& path, QList<AtTimeStruct> &AtTimeStructMap, QList<AreaStruct>& _AreaStructs);

    //保存
    static bool SaveXml(const QString& path, const QList<AtTimeStruct>& AtTimeStructList, const QList<AreaStruct>& _AreaStructList);
};

#endif // AUTOCONTROL_H
